<?php
/**
 * Created by PhpStorm
 * User: Jhinwy
 * Date: 5/10/24
 * Time: 11:18 AM
 */

namespace app\adminapi\lists\shield;

use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\shield\BlackCity;


/**
 * 黑名单IP
 *
 * Class OrderLists
 * @package app\adminapi\lists
 */
class BlackCityLists extends BaseAdminDataLists implements ListsSearchInterface
{


    /**
     * 搜索条件
     *
     * @return array
     */
    public function setSearch(): array
    {
        if ($this->request->get('platform', 0)) {
            return [
                '=' => ['platform']
            ];
        } else {
            return [];
        }

    }


    public function queryWhere(): array
    {
        return [];
    }


    public function count(): int
    {
        return BlackCity::count();
    }


    /**
     * 获取列表
     *
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function lists(): array
    {
        $list = BlackCity::field('id, platform, city, create_time, update_time')
            ->append(['platform_name'])
            ->where($this->searchWhere)
            ->order('create_time', 'desc')
            ->limit($this->limitOffset, $this->limitLength)
            ->select()
            ->toArray();

        foreach ($list as &$item) {
            $item['city'] = implode('，', json_decode($item['city'], true));
        }

        return $list;
    }
}
